﻿Public Class Form1
    '*************************
    '©2013 SimonCoder Software
    'mailto:mreed1972@gmail.com
    '*************************

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'Version needs to adhere to the following:
        'ex: v4.2013.11.14  / Ver. 4.(year).(month).build#
        Dim xver As String = My.Application.Info.Version.ToString
        Me.Text = "SMP v" & xver
        Label2.Text = "v" & xver

        Button3.Visible = False


        'sets the NumericUpDown Min/Max values (The category day can only be 1-5)
        txCategory.Maximum = 5
        txCategory.Minimum = 1

    End Sub

    ''' <summary>
    ''' Will perform the calculation of the user's inputs.
    ''' </summary>
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click


        If txFuelType.SelectedIndex = -1 Then
            MsgBox("Please Select a Fuel Type!")
            txFuelType.Focus()
            Exit Sub
        End If

        If txFuelLoad.SelectedIndex = -1 Then
            MsgBox("Please Select a Fuel Loading!")
            txFuelLoad.Focus()
            Exit Sub
        End If

        If txDistance.Text = Nothing Then
            MsgBox("Please enter a Distance to Target!")
            txDistance.Focus()
            Exit Sub
        End If

        If txBurnSize.Text = Nothing Then
            MsgBox("Please enter a Burn Size (in acres)")
            txBurnSize.Focus()
            Exit Sub
        End If




        'To start calculating:
        'First the user must select the type of fuel and the fuel loading
        'This determines the Available Tons for the burn.
        Dim xvt As New calcfuels.cFuels
        txAvailableTons.Text = xvt.selx(txFuelType.SelectedItem, txFuelLoad.SelectedItem) 'Calculate the Available Tons for the burn.

        'Next, the user must input the Distance to Target, Category Day and Burn Size
        'TODO: Must error check the user inputs

        'The size of the burn * the Tons Available = Total Tons
        txTotalTons.Text = Val(txAvailableTons.Text) * Val(txBurnSize.Text)

        Dim xcv As New calcfuels.altcalc
        txResult.Text = xcv.smpCalc(txCategory.Value, txDistance.Text, txTotalTons.Text)
        If txResult.Text = "Your burn WILL exceed the guidelines" Then
            txExplain.Text = xcv.smpCalc2(txTotalTons.Text, txDistance.Text, txCategory.Value)
            txResult.ForeColor = Color.Yellow
            txResult.BackColor = Color.OrangeRed
            Button3.Visible = True

        Else
            txExplain.Text = ""
            Button3.Visible = False

        End If


    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        txFuelType.SelectedIndex = -1
        txFuelLoad.SelectedIndex = -1
        txDistance.Clear()
        txCategory.Value = 1
        txBurnSize.Clear()
        txAvailableTons.Clear()
        txTotalTons.Clear()
        txResult.Clear()
        txExplain.Clear()
        txResult.BackColor = DefaultBackColor
        txResult.ForeColor = DefaultForeColor


    End Sub






    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        Dim cbs As Integer = txBurnSize.Text
        Dim nbs As Integer
        nbs = cbs / 2
        txBurnSize.Text = nbs
        Button2.PerformClick()

    End Sub
End Class
